<?

class Smutty_Config {

	/**
	 *  constructor
	 *
	 */

	function Smutty_Config() {
		$path = 'application/app.cfg';
		if ( !$f = @fopen($path,'r') )
			new Smutty_Exception_Fatal( 'app.cfg file not found in application/ directory' );
		$lineNum = 1;
		while ( $line = fgets($f) )	{
			if ( substr($line,0,1) == '#' )
				next; // skip comments
			// break the line into name and value
			preg_match( '/^([A-Za-z_\.]*)\s*=\s*([\d\w\/_:]*\s*)\n/', $line, $matches );
			$name = trim( $matches[1] );
			$value = trim( $matches[2] );
			if ( $name && value ) {
				$prop = preg_replace( '/\./', '->', $name );
				eval( "\$this->$prop = '$value';" );
			}
			//else new Smutty_Exception_Fatal( 'config error on line ' . $lineNum );
			$lineNum++;
		}
		fclose( $f );
	}

	/**
	 *  returns the singleton for this object
	 *
	 *  @return Smutty_Config
	 *
	 */

	function getInstance() {
		static $instance;
		if ( $instance == null )
			$instance = new Smutty_Config();
		return $instance;
	}

}

?>